/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AbmAnimal.java
 *
 * Created on 19/06/2011, 23:36:50
 */

package visuales;

import baseDatos.EstadoJaulaDAO;
import entidades.Animal;
import entidades.CausaMuerte;
import java.util.ArrayList;
import java.util.Calendar;
import oracle.sql.DATE;
import java.util.Iterator;
import javax.swing.JOptionPane;
import entidades.Bateria;
import entidades.Camara;
import entidades.Categoria;
import entidades.DetalleMuerte;
import entidades.Empleado;
import entidades.EstadoJaula;
import entidades.Historial;
import entidades.Jaula;
import entidades.TipoEvento;
import gestores.GestorProduccionFacu;
import java.awt.Image;
import java.sql.Date;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;





/**
 *
 * @author Facundo
 */
public class AbmAnimal extends javax.swing.JFrame {

    DATE fecha;
    Calendar c1 = Calendar.getInstance();
    GestorProduccionFacu ga;
    Animal animalNac=new Animal();
    Animal padreNac = new Animal();
    Animal animalMuerte=new Animal();
    Animal padreMuerte = new Animal();
    Animal madreMuerte = new Animal();
    DATE fecha2;
    DATE fecha3;
    DATE fecha4;
    DATE fecha5;
    DATE fechaMuerte;
    Camara ubicacion = new Camara();
    private JFrame pantalla;
    /*
     * primero debemos traer
     */

    /** Creates new form AbmAnimal */
    public AbmAnimal(JFrame padre,int flap) {
        initComponents();
        pantalla=padre;        
        ga=new GestorProduccionFacu();
        generarNombreAnimalNacimiento();
        this.cargarComboCausaMuerte();       
        fecha = new DATE(ga.tomarFechaSistema().dateValue());
        this.cargarComboCategoriaIngreso();
        this.cargarComboCamaraReproduccion();
        this.jTabbedPane1.setSelectedIndex(flap);
         //manejamos la visula de la ventanas
//        this.add(new panelFondo(),BorderLayout.CENTER);
//        this.pack();
//
    }

    //metodo para crear una imagen utilizada como icono de la ventana
     @Override
     public Image getIconImage() {
        Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("visuales/iconoPrincipal.png"));
        return retValue;
    }


//     //Clase que crea un panel para poder poner una imagen de fondo en la ventana
//    public class panelFondo extends javax.swing.JPanel{
//
//        public panelFondo(){
//            initComponents();
//            this.setSize(800,600);
//        }
//
//        @Override
//        public void paintComponent(Graphics g){
//            Dimension tamanio = getSize();
//            ImageIcon imagenFondo = new ImageIcon(getClass().getResource("fondoPrincipal.jpg"));
//            g.drawImage(imagenFondo.getImage(), 0, 0,tamanio.width - 5,tamanio.height - 50,null);
//            setOpaque(false);
//            super.paintComponent(g);
//        }
//    }

    /*
     * deje aca!! debemos cargar el combo de las jaulas....revizar como
     */
    
    private void cargarComboJaulaReproduccion(){
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: "+ ubicacion.getNombre());
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA2222222: "+ ubicacion.getTipo_camara().getNombre());
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: "+ ubicacion.getNombre());
        int codigoCamara = ga.getCodigoCamara(ubicacion.getNombre(), ga.getCodigoTipoCamara(ubicacion.getTipo_camara().getNombre()));
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: "+ codigoCamara);
       
        Iterator iterB =  ubicacion.getBateria().iterator();
        Bateria bat = (Bateria) iterB.next();
        int codigoBateria = ga.getCodigoBateria(bat.getNombre(), codigoCamara);
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: "+ codigoBateria);
        int codigoEstadoLibre = ga.getCodigoEstadoJaula("LIBRE");
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: "+ codigoEstadoLibre);

        ArrayList<Jaula> jaulas = ga.allJaulaDeBateria(codigoBateria, codigoEstadoLibre);
        Iterator iter = jaulas.iterator();
        Jaula aux = null;
        while(iter.hasNext()){
            aux = (Jaula) iter.next();
            cmbJaulaIngreso.addItem(aux);
            System.out.println("AAAAAAAAAAAAAAAAVVVVVVVVVVVVVVVVVVVVVVV: "+aux.getNombre());
        }
        
        if(this.cmbJaulaIngreso.getItemCount()>=1){
            cmbJaulaIngreso.setSelectedIndex(0);
        ArrayList<Jaula> jaulas2 = new ArrayList<Jaula>();
        jaulas2.add((Jaula)cmbJaulaIngreso.getSelectedItem());
        bat.setJaula(jaulas2);
        ArrayList<Bateria> bat3 = new ArrayList<Bateria>();
        bat3.add(bat);
        ubicacion.setBateria(bat3);
        }
        System.out.println("111111111111111111111111111111: "+ubicacion.getNombre());
    }   

    private void cargarComboBateriaReproduccion(int Camara){
        ArrayList<Bateria> baterias = ga.allBateriasDeCamara(Camara);
        Iterator iter = baterias.iterator();
        Bateria aux = null;
        while(iter.hasNext()){
            aux = (Bateria) iter.next();
            cmbBateriaIngreso.addItem(aux);
        }
       // if (this.cmbBateriaIngreso.getItemCount() >= 1){
         //   this.cmbBateriaIngreso.setSelectedIndex(0);
        //}
    }

    private void cargarComboCamaraReproduccion(){
        int tipoCamara = ga.getCodigoTipoCamara("REPRODUCCION");
        int estadoJaula = ga.getCodigoEstadoJaula("LIBRE");
        ArrayList<Camara> camaras = ga.allCamaraXTipoBateriaJaulaXEstado(tipoCamara,estadoJaula);
        Iterator iter = camaras.iterator();
        Camara aux = null;
        while(iter.hasNext()){
            aux = (Camara) iter.next();
            cmbCamaraIngreso.addItem(aux);
        }
       // if (this.cmbCamaraIngreso.getItemCount() >= 1){
         //   this.cmbCamaraIngreso.setSelectedIndex(0);
        //}
    }

    private void cargarComboCategoriaIngreso(){
        ArrayList<Categoria> categorias = ga.allCategorias();
        Iterator iter = categorias.iterator();
        Categoria aux = null;
        while(iter.hasNext()){
            aux = (Categoria) iter.next();
            cmbCategoriaIngreso.addItem(aux);
        }
        this.cmbCategoriaIngreso.setSelectedIndex(0);        
    }

    private void cargarComboCausaMuerte() {
        ArrayList<CausaMuerte> muertes = ga.allCausasMuertes();
       Iterator iter = muertes.iterator();
        CausaMuerte aux = null;
        while (iter.hasNext()) {
            aux = (CausaMuerte) iter.next();
            cmbCausaMuerte.addItem(aux);
          } 
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */

    /*
     * Metodo que busca en la base de datos el ultimo nombre de un gazapo registrado
     * y le suma uno, luego lo muestra en la pantalla, en el campo txtNombre
     */
    private void generarNombreAnimalNacimiento(){
        //obtenemos el año actual y la letra correspondiente a este año
        String fecha_actual = ga.tomarFechaSistema().dateValue().toString();
        int año =  Integer.parseInt(fecha_actual.substring(0, 4));
        System.out.println("Año: " +año + "   fecha: " + ga.tomarFechaSistema().dateValue());
        String letra = ga.getLetra(año);
        System.out.println("LETRA: "+ letra);

        //obtenemos todos los animales de la base
        //de cada animal preguntamos si tiene el mismo año de nacimiento al actual
        //luego determinamos cual es el que tiene el nombre mas grande y a ese le sumamos 1
        ArrayList<Animal> animales = ga.allAnimales();
        Iterator iter = animales.iterator();        
        Animal aux = null;
        int nombre = 0;
        System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS: "+nombre);        
        while (iter.hasNext()) {
            aux = (Animal) iter.next();
            if(Integer.parseInt(aux.getFecha_nacimiento().dateValue().toString().substring(0, 4)) == año){
                System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS: "+año);
                if(Integer.parseInt(aux.getNombre().substring(3)) > nombre){
                    System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS: "+nombre);
                   // nombre = Integer.parseInt(aux.getNombre().substring(3, 4));
                     nombre = Integer.parseInt(aux.getNombre().substring(3));
                    System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS2222222: "+nombre);
                }
            }
          }

        //debemos armar el nombre
        if(nombre != 0){
            //hay nombres existentes para esta año
            nombre++;
            txtNombre.setText("NN" + letra + nombre);
            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa NN" + letra + nombre);
        }
        else{
            //no hay nombre registrados para este año
            txtNombre.setText("NN" + letra + 1);
        }  
    }

    private void generarNombreAnimalIngreso(int año){
       
        //buscamos la letra correspondiente al año que viene por parametro
        String letra = ga.getLetra(año);
        System.out.println("LETRA: "+ letra);

        //obtenemos todos los animales de la base
        //de cada animal preguntamos si tiene el mismo año de nacimiento al que viene por parametro
        //luego determinamos cual es el que tiene el nombre mas grande y a ese le sumamos 1
        ArrayList<Animal> animales = ga.allAnimales();
        Iterator iter = animales.iterator();
        Animal aux = null;
        int nombre = 0;
        System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS: "+nombre);
        while (iter.hasNext()) {
            aux = (Animal) iter.next();
            if(Integer.parseInt(aux.getFecha_nacimiento().dateValue().toString().substring(0, 4)) == año){
                System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS: "+año);
                if(Integer.parseInt(aux.getNombre().substring(3, 4)) > nombre){
                    System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS: "+nombre);
                    nombre = Integer.parseInt(aux.getNombre().substring(3, 4));
                    System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSS2222222: "+nombre);
                }
            }
          }

        //debemos armar el nombre
        if(nombre != 0){
            //hay nombres existentes para esta año
            nombre++;
            txtNombreIngreso.setText("NN" + letra + nombre);
        }
        else{
            //no hay nombre registrados para este año
            txtNombreIngreso.setText("NN" + letra + 1);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        btnSalir = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtMadreNacimineto = new javax.swing.JTextField();
        btnBuscarMadreNacimiento = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtPadreNacimiento = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        txtUbicacionBateria = new javax.swing.JTextField();
        lblBateria = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtUbicacionJaula = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtFechaNacimientoDestete = new javax.swing.JFormattedTextField();
        txtFechaNacimiento = new javax.swing.JFormattedTextField();
        jLabel16 = new javax.swing.JLabel();
        txtFechaNacimientoRalgro = new javax.swing.JFormattedTextField();
        jLabel18 = new javax.swing.JLabel();
        txtFechaNacimientoPeleteo = new javax.swing.JFormattedTextField();
        btnCancelarNacimiento = new javax.swing.JButton();
        btnRegistrarNacimiento = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        lblFecha2 = new javax.swing.JLabel();
        txtNombreIngreso = new javax.swing.JTextField();
        lblNombre2 = new javax.swing.JLabel();
        lblPadre4 = new javax.swing.JLabel();
        btnRadioHembraIngreso = new javax.swing.JRadioButton();
        btnRadioMachoIngreso = new javax.swing.JRadioButton();
        cmbCategoriaIngreso = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        cmbCamaraIngreso = new javax.swing.JComboBox();
        cmbBateriaIngreso = new javax.swing.JComboBox();
        cmbJaulaIngreso = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        btnIngresoValidar = new javax.swing.JButton();
        txtFechaNacimientoIngreso = new javax.swing.JFormattedTextField();
        btnCancelarIngreso = new javax.swing.JButton();
        btnRegistrarIngreso = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        txtAnimalMuerte = new javax.swing.JFormattedTextField();
        btnBuscarAnimalMuerte = new javax.swing.JButton();
        jPanel18 = new javax.swing.JPanel();
        lblMadre3 = new javax.swing.JLabel();
        lblPadre5 = new javax.swing.JLabel();
        txtMadreMuerte = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        txtPadreMuerte = new javax.swing.JFormattedTextField();
        txtFechaNacimientoMuerte = new javax.swing.JFormattedTextField();
        jPanel8 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        txtBateria = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        txtJaula = new javax.swing.JTextField();
        jPanel21 = new javax.swing.JPanel();
        cmbCausaMuerte = new javax.swing.JComboBox();
        lblCausa = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtFechaMuerte = new javax.swing.JFormattedTextField();
        btnRegstrarMuerte = new javax.swing.JButton();
        btnCancelarMuerte = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("PampaChin- Animales");

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Nombre del gazapo:"));

        jLabel1.setText("Nombre:");

        txtNombre.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(269, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos heredados:"));

        jLabel2.setText("Madre:");

        btnBuscarMadreNacimiento.setText("Buscar");
        btnBuscarMadreNacimiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarMadreNacimientoActionPerformed(evt);
            }
        });

        jLabel3.setText("Padre:");

        txtPadreNacimiento.setEditable(false);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Ubicacion"));

        txtUbicacionBateria.setEditable(false);

        lblBateria.setText("Bateria :");

        jLabel4.setText("Jaula :");

        txtUbicacionJaula.setEditable(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(lblBateria))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)))
                .addGap(21, 21, 21)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtUbicacionJaula)
                    .addComponent(txtUbicacionBateria, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))
                .addContainerGap(290, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBateria)
                    .addComponent(txtUbicacionBateria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtUbicacionJaula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtPadreNacimiento, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtMadreNacimineto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                .addGap(33, 33, 33)
                .addComponent(btnBuscarMadreNacimiento)
                .addGap(203, 203, 203))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(28, 28, 28))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(btnBuscarMadreNacimiento)
                    .addComponent(txtMadreNacimineto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPadreNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Fechas:"));

        jLabel5.setText("Fecha de nacimiento:");

        jLabel6.setText("Fecha de destete:");

        txtFechaNacimientoDestete.setEditable(false);
        txtFechaNacimientoDestete.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));

        txtFechaNacimiento.setEditable(false);
        txtFechaNacimiento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));

        jLabel16.setText("Fecha de peleteo:");

        txtFechaNacimientoRalgro.setEditable(false);
        txtFechaNacimientoRalgro.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));

        jLabel18.setText("Fecha de ralgro:");

        txtFechaNacimientoPeleteo.setEditable(false);
        txtFechaNacimientoPeleteo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtFechaNacimiento)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(15, 15, 15)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(txtFechaNacimientoDestete, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel16))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(txtFechaNacimientoRalgro, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtFechaNacimientoPeleteo, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtFechaNacimientoDestete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtFechaNacimientoRalgro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtFechaNacimientoPeleteo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel4Layout.createSequentialGroup()
                            .addComponent(jLabel18)
                            .addGap(26, 26, 26))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel16))))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        btnCancelarNacimiento.setText("Cancelar");
        btnCancelarNacimiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarNacimientoActionPerformed(evt);
            }
        });

        btnRegistrarNacimiento.setText("Registrar");
        btnRegistrarNacimiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistrarNacimientoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(btnRegistrarNacimiento)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancelarNacimiento))
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelarNacimiento)
                    .addComponent(btnRegistrarNacimiento))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Registrar Nacimiento", jPanel1);

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos iniciales"));

        lblFecha2.setText("Fecha Nacimiento :");

        txtNombreIngreso.setEditable(false);

        lblNombre2.setText("Nombre :");

        lblPadre4.setText("Sexo :");

        buttonGroup1.add(btnRadioHembraIngreso);
        btnRadioHembraIngreso.setText("Hembra");

        buttonGroup1.add(btnRadioMachoIngreso);
        btnRadioMachoIngreso.setSelected(true);
        btnRadioMachoIngreso.setText("Macho");

        jLabel13.setText("Categoria :");

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Nueva Ubicacion:"));

        jLabel7.setText("Bateria:");

        jLabel14.setText("Jaula:");

        jLabel15.setText("Camara:");

        cmbCamaraIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbCamaraIngresoActionPerformed(evt);
            }
        });

        cmbBateriaIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbBateriaIngresoActionPerformed(evt);
            }
        });

        cmbJaulaIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbJaulaIngresoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cmbBateriaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cmbJaulaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(18, 18, 18)
                        .addComponent(cmbCamaraIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(142, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(cmbCamaraIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cmbBateriaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(cmbJaulaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jLabel17.setForeground(new java.awt.Color(255, 0, 0));
        jLabel17.setText("(DD/MM/AAAA)");

        btnIngresoValidar.setText("Validar");
        btnIngresoValidar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIngresoValidarActionPerformed(evt);
            }
        });

        txtFechaNacimientoIngreso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addGap(18, 18, 18)
                        .addComponent(cmbCategoriaIngreso, 0, 234, Short.MAX_VALUE)
                        .addGap(154, 154, 154))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(lblFecha2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFechaNacimientoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnIngresoValidar)
                        .addContainerGap(97, Short.MAX_VALUE))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel10Layout.createSequentialGroup()
                                .addComponent(lblNombre2)
                                .addGap(18, 18, 18)
                                .addComponent(txtNombreIngreso))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel10Layout.createSequentialGroup()
                                .addComponent(lblPadre4)
                                .addGap(27, 27, 27)
                                .addComponent(btnRadioHembraIngreso)))
                        .addGap(18, 18, 18)
                        .addComponent(btnRadioMachoIngreso)
                        .addGap(85, 85, 85))))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFecha2)
                    .addComponent(jLabel17)
                    .addComponent(btnIngresoValidar)
                    .addComponent(txtFechaNacimientoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre2)
                    .addComponent(txtNombreIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPadre4)
                    .addComponent(btnRadioHembraIngreso)
                    .addComponent(btnRadioMachoIngreso))
                .addGap(18, 18, 18)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(cmbCategoriaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        btnCancelarIngreso.setText("Cancelar");
        btnCancelarIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarIngresoActionPerformed(evt);
            }
        });

        btnRegistrarIngreso.setText("Registrar");
        btnRegistrarIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistrarIngresoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(btnRegistrarIngreso)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelarIngreso))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRegistrarIngreso)
                    .addComponent(btnCancelarIngreso))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Registrar Ingreso", jPanel6);

        jPanel17.setBorder(javax.swing.BorderFactory.createTitledBorder("Seleccionar Animal"));

        jLabel10.setText("Animal:");

        btnBuscarAnimalMuerte.setText("Buscar");
        btnBuscarAnimalMuerte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarAnimalMuerteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(jPanel17Layout);
        jPanel17Layout.setHorizontalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(txtAnimalMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnBuscarAnimalMuerte)
                .addContainerGap(172, Short.MAX_VALUE))
        );
        jPanel17Layout.setVerticalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(btnBuscarAnimalMuerte)
                    .addComponent(txtAnimalMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel18.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Animal", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        lblMadre3.setText("Madre ");

        lblPadre5.setText("Padre:");

        txtMadreMuerte.setEditable(false);

        jLabel11.setText("Fecha Nacimiento:");

        txtPadreMuerte.setEditable(false);

        txtFechaNacimientoMuerte.setEditable(false);

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Ubicacion"));

        jLabel12.setText("Bateria:");

        txtBateria.setEditable(false);

        jLabel8.setText("Jaula:");

        txtJaula.setEditable(false);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel12))
                .addGap(18, 18, 18)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtJaula)
                    .addComponent(txtBateria, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))
                .addContainerGap(267, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtBateria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtJaula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
        jPanel18.setLayout(jPanel18Layout);
        jPanel18Layout.setHorizontalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(lblPadre5)
                            .addComponent(lblMadre3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtFechaNacimientoMuerte, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMadreMuerte, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                            .addComponent(txtPadreMuerte))))
                .addContainerGap())
        );
        jPanel18Layout.setVerticalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMadreMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMadre3))
                .addGap(8, 8, 8)
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPadre5)
                    .addComponent(txtPadreMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtFechaNacimientoMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel21.setBorder(javax.swing.BorderFactory.createTitledBorder("Muerte"));

        lblCausa.setText("Causa de muerte :");

        jLabel9.setText("Fecha Fallecimiento:");

        javax.swing.GroupLayout jPanel21Layout = new javax.swing.GroupLayout(jPanel21);
        jPanel21.setLayout(jPanel21Layout);
        jPanel21Layout.setHorizontalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel21Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel21Layout.createSequentialGroup()
                        .addComponent(lblCausa)
                        .addGap(18, 18, 18)
                        .addComponent(cmbCausaMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel21Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtFechaMuerte)))
                .addContainerGap(207, Short.MAX_VALUE))
        );
        jPanel21Layout.setVerticalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel21Layout.createSequentialGroup()
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCausa)
                    .addComponent(cmbCausaMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtFechaMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        btnRegstrarMuerte.setText("Registrar");
        btnRegstrarMuerte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegstrarMuerteActionPerformed(evt);
            }
        });

        btnCancelarMuerte.setText("Cancelar");
        btnCancelarMuerte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarMuerteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnRegstrarMuerte)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelarMuerte))
                    .addComponent(jPanel17, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel18, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel18, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRegstrarMuerte)
                    .addComponent(btnCancelarMuerte))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Registrar Muerte", jPanel5);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(468, Short.MAX_VALUE)
                .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSalir)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnRegistrarNacimientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarNacimientoActionPerformed
            if (animalNac != null){
            Animal ani = new Animal();
            ani.setNombre(txtNombre.getText());
            ani.setMadre(animalNac);
            ani.setPadre(padreNac);
            ani.setUbicacion(animalNac.getUbicacion());
            ani.setFecha_nacimiento(fecha2);
            ani.setFecha_destete_aprox(fecha3);
            ani.setFecha_ralgro_aprox(fecha4);
            ani.setFecha_peleteado_aprox(fecha5);
            System.out.println(fecha3.toString());
            ga.insertarAnimal(ani);



            Historial hist=new Historial();
            hist.setAnimal(ani);
            hist.setFecha(fecha);
            hist.setTipo_evento(new TipoEvento("NACIMIENTO", "nacimiento"));
            hist.setDescripcion("Se registra nacimiento del gazapo");
            ga.insertarHistorial(hist);
     




            txtMadreNacimineto.setText("");
            txtPadreNacimiento.setText("");
            txtUbicacionBateria.setText("");
            txtUbicacionJaula.setText("");
            txtFechaNacimiento.setText("");
            txtFechaNacimientoDestete.setText("");
            txtFechaNacimientoRalgro.setText("");
            txtFechaNacimientoPeleteo.setText("");
            
            generarNombreAnimalNacimiento();
            animalNac = null;
            padreNac = null;
            }
            
            //anulamos todos los datos de la ventana de ingreso
             txtFechaNacimientoIngreso.setText("");
             btnRadioMachoIngreso.setSelected(true);
             cmbCategoriaIngreso.setSelectedIndex(0);
             cmbCamaraIngreso.setSelectedIndex(0);
             cmbBateriaIngreso.removeAllItems();
             cmbJaulaIngreso.removeAllItems();
            
    }//GEN-LAST:event_btnRegistrarNacimientoActionPerformed
    private void btnBuscarMadreNacimientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarMadreNacimientoActionPerformed
         try {
                String nombre = txtMadreNacimineto.getText();
                System.out.println("0000000000000000000000000000000"+nombre);
                animalNac = ga.getAnimalHembra(nombre);
                
                if (animalNac != null) {
                    
                    padreNac = ga.getPadre(animalNac);
                    if(padreNac!=null)
                        txtPadreNacimiento.setText(padreNac.getNombre());
                    System.out.println("qqqqqqqqqqqqqqqqqqqq "+animalNac.getUbicacion().getTipo_camara().getNombre());
                    Iterator iter = animalNac.getUbicacion().getBateria().iterator();
                    Bateria bat = (Bateria) iter.next();
                    Iterator iter2 = bat.getJaula().iterator();
                    Jaula jau = (Jaula) iter2.next();
                    txtUbicacionBateria.setText(bat.getNombre());
                    txtUbicacionJaula.setText(jau.getNombre());
                    fecha2=new DATE(fecha.dateValue());
                    //txtFechaNacimiento.setText(String.valueOf(fecha2.dateValue()));
                    txtFechaNacimiento.setText(String.valueOf(fecha.dateValue()));
                    System.out.println((int)Integer.parseInt(ga.getParametro("DIAD").getValor()));
                    java.sql.Date fec = new java.sql.Date(fecha.dateValue().getYear(), fecha.dateValue().getMonth(), fecha.dateValue().getDate()+ (int)Integer.parseInt(ga.getParametro("DIAD").getValor()));
                    java.sql.Date fec2 = new java.sql.Date(fecha.dateValue().getYear(), fecha.dateValue().getMonth(), fecha.dateValue().getDate()+(int)Integer.parseInt(ga.getParametro("DIAR").getValor()));
                    java.sql.Date fec3 = new java.sql.Date(fecha.dateValue().getYear(), fecha.dateValue().getMonth(), fecha.dateValue().getDate()+(int)Integer.parseInt(ga.getParametro("DIAP").getValor()));

                    fecha5=new DATE(fec3);
                    fecha4=new DATE(fec2);
                    fecha3=new DATE(fec);

                    txtFechaNacimientoDestete.setText(String.valueOf(fecha3.dateValue()));
                    txtFechaNacimientoRalgro.setText(String.valueOf(fecha4.dateValue()));
                    txtFechaNacimientoPeleteo.setText(String.valueOf(fecha5.dateValue()));
         
                    
                 } 
                else {
                JOptionPane.showMessageDialog(null, "El nombre de animal ingresado es incorrecto", "Advertencia", JOptionPane.ERROR_MESSAGE);
            }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(null, "Error ocurrido!!", "Atencion", JOptionPane.ERROR_MESSAGE);
           
            return;
        }
    }//GEN-LAST:event_btnBuscarMadreNacimientoActionPerformed

    private void btnCancelarNacimientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarNacimientoActionPerformed
        // TODO add your handling code here:

        txtMadreNacimineto.setText("");
        txtPadreNacimiento.setText("");
        txtUbicacionBateria.setText("");
        txtUbicacionJaula.setText("");
        txtFechaNacimiento.setText("");
        txtFechaNacimientoDestete.setText("");
        txtFechaNacimientoRalgro.setText("");
        txtFechaNacimientoPeleteo.setText("");
    }//GEN-LAST:event_btnCancelarNacimientoActionPerformed
 
    private void btnBuscarAnimalMuerteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarAnimalMuerteActionPerformed
       try {
               //DETERMINAR PRIMERO SI EL ANIMAL ESTA MUERTO
                String nombre = new String(txtAnimalMuerte.getText());

                animalMuerte = ga.getAnimal(nombre);
                if (animalMuerte != null)
                {

                    madreMuerte = animalMuerte.getMadre();
                    padreMuerte = animalMuerte.getPadre();

                    if(madreMuerte != null)
                        txtMadreMuerte.setText(madreMuerte.getNombre());
                    if(padreMuerte != null)
                        txtPadreMuerte.setText(padreMuerte.getNombre());

                    Iterator iter = animalMuerte.getUbicacion().getBateria().iterator();
                    Bateria bat = (Bateria) iter.next();
                    Iterator iter2 = bat.getJaula().iterator();
                    Jaula jau = (Jaula) iter2.next();

                    txtBateria.setText(bat.getNombre());
                    txtJaula.setText(jau.getNombre());

                    txtFechaNacimientoMuerte.setText(String.valueOf(animalMuerte.getFecha_nacimiento().dateValue()));

                    fechaMuerte= ga.tomarFechaSistema();
                    txtFechaMuerte.setText(String.valueOf(fechaMuerte.dateValue()));
                    
                } 
                else {
                JOptionPane.showMessageDialog(null, "El nombre de animal ingresado es icorrecto", "Advertencia", JOptionPane.ERROR_MESSAGE);

          }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(null, "Error ocurrido!!", "Atencion", JOptionPane.ERROR_MESSAGE);
            return;
        }        // TODO add your handling code here:
    }//GEN-LAST:event_btnBuscarAnimalMuerteActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
       this.dispose();
       this.pantalla.setVisible(true);
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnRegstrarMuerteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegstrarMuerteActionPerformed
        /*
         * Metodo para registrar la muerte de un animal!!
         */
    TipoEvento tipoeve = ga.getTipoEvento("MUERTE");
    if(tipoeve!=null){
        /*
         * Creamos los objetos detalle de muerte, su array e historial
         */
        DetalleMuerte det = new DetalleMuerte();
        det.setFecha_muerte(fechaMuerte);
        det.setTipo_muerte((CausaMuerte)cmbCausaMuerte.getSelectedItem());//fgdfgdfgfdgfdg

        ArrayList<DetalleMuerte> lista = new ArrayList<DetalleMuerte>();
        lista.add(det);

        Historial his = new Historial();
        his.setAnimal(animalMuerte);
        his.setDescripcion("FALLECIMIENTO DE GAZAPO");
        his.setEmpleado(ga.getEmpleado(1));
        his.setFecha(fechaMuerte);
        his.setTipo_evento(tipoeve);
        his.setDetalle_muerte(lista);

        ga.insertarHistorialMuerte(his);

        txtMadreMuerte.setText("");
        txtPadreMuerte.setText("");
        txtBateria.setText("");
        txtAnimalMuerte.setText("");
        txtJaula.setText("");
        txtFechaNacimientoMuerte.setText("");

        animalMuerte= null;
        padreMuerte = null;
        madreMuerte = null;
    }


    }//GEN-LAST:event_btnRegstrarMuerteActionPerformed

    private void btnCancelarMuerteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarMuerteActionPerformed
       txtMadreMuerte.setText("");
        txtPadreMuerte.setText("");
        txtBateria.setText("");
         txtAnimalMuerte.setText("");
        txtJaula.setText("");
        txtFechaNacimientoMuerte.setText("");
    }//GEN-LAST:event_btnCancelarMuerteActionPerformed

    private void btnRegistrarIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarIngresoActionPerformed
        // TODO add your handling code here:
        if((txtFechaNacimientoIngreso.getText()!=null) && (this.cmbJaulaIngreso.getSelectedItem() != null && this.cmbCategoriaIngreso.getSelectedItem()!=null)){
            if((this.txtFechaNacimientoIngreso.getText().length()==10) && (this.txtFechaNacimientoIngreso.getText().substring(2, 3).compareTo("/")==0) && (this.txtFechaNacimientoIngreso.getText().substring(5,6).compareTo("/")==0)){

            System.out.println("TAMAÑO DE LA CADENA: "+this.txtFechaNacimientoIngreso.getText().length());
            String comprobar1 = this.txtFechaNacimientoIngreso.getText().substring(2, 3);
            String comprobar2 = this.txtFechaNacimientoIngreso.getText().substring(5, 6);
            System.out.println("CARACTERES: " + comprobar1 + "     "+ comprobar2);

            Animal ani = new Animal();
            ani.setNombre(txtNombreIngreso.getText());
            
            if(this.btnRadioHembraIngreso.isSelected()){
                char a='H';
                ani.setSexo(ga.getSexo(a));
            }else{
                char a='M';
                ani.setSexo(ga.getSexo(a));
            }
            
            ani.setUbicacion(ubicacion);
            ani.setCategoria((Categoria)this.cmbCategoriaIngreso.getSelectedItem());
            
            String fecha_dia = txtFechaNacimientoIngreso.getText().substring(0,2);
            System.out.println(fecha_dia);
            String fecha_año = txtFechaNacimientoIngreso.getText().substring(6);
            System.out.println(fecha_año);
            String fecha_mes = txtFechaNacimientoIngreso.getText().substring(3, 5);
            System.out.println(fecha_mes);

            System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQ: "+fecha_año+fecha_mes+fecha_dia);
            
            //DATE fecha_nace = new DATE("2011-03-02 00:00:00");
            DATE fecha_total = new DATE(fecha_año+"-"+fecha_mes+"-"+fecha_dia+" 00:00:00");

           
            System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQ22222222222222: "+fecha_total.dateValue());
            System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQ22222222222222: "+fecha_total);

            //DATE fecha_nace2 = new DATE(this.txtFechaNacimientoIngreso.getText());
            //System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQ33333333333333: "+fecha_nace2.dateValue());
            ani.setFecha_nacimiento(fecha_total);

            
            

            try
            {
                ga.insertarAnimal(ani);

                Historial hist=new Historial();
                hist.setAnimal(ani);
                hist.setFecha(fecha);
                hist.setTipo_evento(new TipoEvento("COMPRA", "compra de gazapo"));
                ga.insertarHistorial(hist);

                txtFechaNacimientoIngreso.setText("");
                btnRadioMachoIngreso.setSelected(true);
                //cmbCamaraIngreso.removeAllItems();
                cmbBateriaIngreso.removeAllItems();
                cmbJaulaIngreso.removeAllItems();
                //this.cargarComboCamaraReproduccion();
                generarNombreAnimalNacimiento();

                //anulamos todos los datos de la ventana de nacimiento
                txtMadreNacimineto.setText("");
                txtPadreNacimiento.setText("");
                txtUbicacionBateria.setText("");
                txtUbicacionJaula.setText("");
                txtFechaNacimiento.setText("");
                txtFechaNacimientoDestete.setText("");
                txtNombreIngreso.setText("");
                animalNac = null;
                padreNac = null;
            }
            catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(null, "Error ocurrido!!", "Atencion", JOptionPane.ERROR_MESSAGE);
                return;
            }
            }
            else{
                JOptionPane.showMessageDialog(null, "Fecha con formato incorrecto", "Atencion", JOptionPane.ERROR_MESSAGE);
                this.txtFechaNacimientoIngreso.setText("");
            }
        }else{
                JOptionPane.showMessageDialog(null, "Falta seleccion de combos..", "Atencion", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_btnRegistrarIngresoActionPerformed

    private void btnCancelarIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarIngresoActionPerformed
        // TODO add your handling code here:
        //txtNombreIngreso.setText("");       
        txtFechaNacimientoIngreso.setText("");
        btnRadioMachoIngreso.setSelected(true);
        cmbCategoriaIngreso.setSelectedIndex(0);
        cmbCamaraIngreso.setSelectedIndex(0);
        cmbBateriaIngreso.removeAllItems();
        cmbJaulaIngreso.removeAllItems();
        txtNombreIngreso.setText("");

    }//GEN-LAST:event_btnCancelarIngresoActionPerformed

    /*
     * Debemos traer un objeto ubicacion, seria una camara de reproduccion con sus respectivos 
     * baterias y jaulas
     * 
     */
    private void cmbCamaraIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbCamaraIngresoActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:
        if(this.cmbCamaraIngreso.getSelectedItem()!=null){
            Camara cam = (Camara) this.cmbCamaraIngreso.getSelectedItem();
            this.cmbBateriaIngreso.removeAllItems();
            this.cmbJaulaIngreso.removeAllItems();
            int codBateria = ga.getCodigoCamara(cam.getNombre(), ga.getCodigoTipoCamara(cam.getTipo_camara().getNombre()));
            if(codBateria != -1){
                System.out.println("XXXXXXX: "+ubicacion.getNombre());
                ubicacion= (Camara)this.cmbCamaraIngreso.getSelectedItem();
                this.cargarComboBateriaReproduccion(codBateria);
                System.out.println("XXXXXXX: "+ubicacion.getNombre());
            }
            System.out.println("ZZZZZZZZZZZZZZZZZZZZZZZZZZZ: "+codBateria);
        }

    }//GEN-LAST:event_cmbCamaraIngresoActionPerformed

    private void cmbBateriaIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbBateriaIngresoActionPerformed
        // TODO add your handling code here:
        System.out.println("CCCCCCCCCCCCCCCCCCCCC11111111: "+ubicacion.getNombre());
        if(this.cmbBateriaIngreso.getSelectedItem()!=null){
            this.cmbJaulaIngreso.removeAllItems();
            ArrayList<Bateria> baterias = new ArrayList<Bateria>();
            Bateria bata = (Bateria)this.cmbBateriaIngreso.getSelectedItem();
            baterias.add(bata);
            ubicacion.setBateria(baterias);
            System.out.println("CCCCCCCCCCCCCCCCCCCCC: "+ubicacion.getNombre());
            System.out.println("CCCCCCCCCCCCCCCCCCCCC: "+ bata.getNombre());
            this.cargarComboJaulaReproduccion();
        }
        
    }//GEN-LAST:event_cmbBateriaIngresoActionPerformed

    private void cmbJaulaIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbJaulaIngresoActionPerformed
        // TODO add your handling code here:
     
        if(this.cmbJaulaIngreso.getSelectedItem() != null){
            Jaula jau = (Jaula) this.cmbJaulaIngreso.getSelectedItem();
            ArrayList<Jaula> jaulas = new ArrayList<Jaula>();
            jaulas.add(jau);
            Iterator iter =  ubicacion.getBateria().iterator();
            Bateria bat = (Bateria) iter.next();
            bat.setJaula(jaulas);
            ArrayList<Bateria> bat3 = new ArrayList<Bateria>();
            bat3.add(bat);
            ubicacion.setBateria(bat3);
        }

    }//GEN-LAST:event_cmbJaulaIngresoActionPerformed

    private void btnIngresoValidarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIngresoValidarActionPerformed
        // TODO add your handling code here:
         if(txtFechaNacimientoIngreso.getText()!=null){
             System.out.println("----------------------------------------------------"+txtFechaNacimientoIngreso.getText());
            if(this.txtFechaNacimientoIngreso.getText().length()==10){
                if((this.txtFechaNacimientoIngreso.getText().substring(2, 3).compareTo("/")==0) && (this.txtFechaNacimientoIngreso.getText().substring(5,6).compareTo("/")==0)){



                    System.out.println("TAMAÑO DE LA CADENA: "+this.txtFechaNacimientoIngreso.getText().length());
                    String comprobar1 = this.txtFechaNacimientoIngreso.getText().substring(2, 3);
                    String comprobar2 = this.txtFechaNacimientoIngreso.getText().substring(5, 6);
                    System.out.println("CARACTERES: " + comprobar1 + "     "+ comprobar2);

                    String fecha_dia = txtFechaNacimientoIngreso.getText().substring(0,2);
                    System.out.println(fecha_dia);
                    String fecha_año = txtFechaNacimientoIngreso.getText().substring(6);
                    System.out.println(fecha_año);
                    String fecha_mes = txtFechaNacimientoIngreso.getText().substring(3, 5);
                    System.out.println(fecha_mes);
                    
                    DATE fecha_total = new DATE(fecha_año+"-"+fecha_mes+"-"+fecha_dia+" 00:00:00");
                    
                    System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQ: "+fecha_año+fecha_mes+fecha_dia);

                    //if(Integer.parseInt(fecha_dia)>=1 && Integer.parseInt(fecha_dia)<=31)
                    //buscamos la fecha y el año actual
                    int año = Integer.parseInt(ga.tomarFechaSistema().dateValue().toString().substring(0, 4));
                    System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQ: "+año);

                    if(Integer.parseInt(fecha_año)>2000 && Integer.parseInt(fecha_año)<= año){
                        this.generarNombreAnimalIngreso(Integer.parseInt(fecha_año));
                    }                   
                }
                else{
                    JOptionPane.showMessageDialog(null, "Fecha con formato incorrecto", "Atencion", JOptionPane.ERROR_MESSAGE);
                    this.txtFechaNacimientoIngreso.setText("");
                }
            }
            else{
                JOptionPane.showMessageDialog(null, "Numero de caracteres incorrectos", "Atencion", JOptionPane.ERROR_MESSAGE);
                this.txtFechaNacimientoIngreso.setText("");
            }
         }
         else{
            JOptionPane.showMessageDialog(null, "Debe completar la fecha de nacimiento", "Atencion", JOptionPane.ERROR_MESSAGE);
         }
    }//GEN-LAST:event_btnIngresoValidarActionPerformed
  private void muerteSeleccionado() {
  //      ga.muerteSeleccionado((CausaMuerte) cmbCausaMuerte.getSelectedItem());
  }
 
    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new AbmAnimal().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscarAnimalMuerte;
    private javax.swing.JButton btnBuscarMadreNacimiento;
    private javax.swing.JButton btnCancelarIngreso;
    private javax.swing.JButton btnCancelarMuerte;
    private javax.swing.JButton btnCancelarNacimiento;
    private javax.swing.JButton btnIngresoValidar;
    private javax.swing.JRadioButton btnRadioHembraIngreso;
    private javax.swing.JRadioButton btnRadioMachoIngreso;
    private javax.swing.JButton btnRegistrarIngreso;
    private javax.swing.JButton btnRegistrarNacimiento;
    private javax.swing.JButton btnRegstrarMuerte;
    private javax.swing.JButton btnSalir;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cmbBateriaIngreso;
    private javax.swing.JComboBox cmbCamaraIngreso;
    private javax.swing.JComboBox cmbCategoriaIngreso;
    private javax.swing.JComboBox cmbCausaMuerte;
    private javax.swing.JComboBox cmbJaulaIngreso;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblBateria;
    private javax.swing.JLabel lblCausa;
    private javax.swing.JLabel lblFecha2;
    private javax.swing.JLabel lblMadre3;
    private javax.swing.JLabel lblNombre2;
    private javax.swing.JLabel lblPadre4;
    private javax.swing.JLabel lblPadre5;
    private javax.swing.JFormattedTextField txtAnimalMuerte;
    private javax.swing.JFormattedTextField txtBateria;
    private javax.swing.JFormattedTextField txtFechaMuerte;
    private javax.swing.JFormattedTextField txtFechaNacimiento;
    private javax.swing.JFormattedTextField txtFechaNacimientoDestete;
    private javax.swing.JFormattedTextField txtFechaNacimientoIngreso;
    private javax.swing.JFormattedTextField txtFechaNacimientoMuerte;
    private javax.swing.JFormattedTextField txtFechaNacimientoPeleteo;
    private javax.swing.JFormattedTextField txtFechaNacimientoRalgro;
    private javax.swing.JTextField txtJaula;
    private javax.swing.JFormattedTextField txtMadreMuerte;
    private javax.swing.JTextField txtMadreNacimineto;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNombreIngreso;
    private javax.swing.JFormattedTextField txtPadreMuerte;
    private javax.swing.JTextField txtPadreNacimiento;
    private javax.swing.JTextField txtUbicacionBateria;
    private javax.swing.JTextField txtUbicacionJaula;
    // End of variables declaration//GEN-END:variables

}
